home *** CD-ROM | disk | FTP | other *** search
- Path: mother.usf.edu!news
- From: gohel@csee.usf.edu (Himanshu Gohel)
- Newsgroups: comp.lang.c
- Subject: Re: #include "" for large programs.
- Followup-To: comp.lang.c
- Date: 14 Apr 1996 21:45:54 GMT
- Organization: Geometric Modeling and Computer Graphics Group, USF Tampa, FL.
- Message-ID: <4krrmi$7ef@mother.usf.edu>
- References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan>
- Reply-To: gohel@csee.usf.edu
- NNTP-Posting-Host: pixel.csee.usf.edu
-
- In article <Pine.SUN.3.92.960411195730.24973A-100000@suntan>, "Carlos Diaz (CS)" <cdiaz@eng.usf.edu> writes:
-
- > All works well when I compile the programs, except when part2.h has
- >#define constants (I've been advised by my professor to use #define for
- >constants over 'const type var_name'). My compiler returns a fatal error
- >reporting that the symbol in the #define is not defined.
- > For example if #define EQUAL 0 is part of part2.h, I'm told that the
- >symbol EQUAL is not defined. But if I put the #define inside main.c, I'm
- >told that I've defined EQUAL TWICE, once in part2.h and again within
- >main.
-
- The way to avoid multiple definitions (and similarly multiple inclusions
- of .h files) is to do the following:
-
- #ifndef __MYHEADERFILE__
- #define __MYHEADERFILE__
- ...all your header file stuff here...
- #endif
-
- Now you can include this .h file as many times as you want and you
- won't have problems with multiple defintions because of the #ifndef.
-
- Also, there is a place for the const keyword, but in C that cannot
- be put in a .h file. It has to go in a C file.
-
- --
- Himanshu Gohel, gohel@csee.usf.edu | You only have to do very few
- WEB URL: http://www.csee.usf.edu/~gohel/ | things right in your life as
- Geometric Modeling & Graphics Research Group | long as you don't do too many
- U of South Florida, Tampa, FL. USA. | things wrong - Warren Buffett
-
-
-